package July;

import java.util.Scanner;

public class Day0727 {
    public static void main1(String[] args) {
        //完美数
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int res = count(n);
        System.out.println(res);
    }

    private static int count(int n) {
        int count = 0;
        for (int i = 1; i <= n ; i++) {
            if (Perfect(i))
                count += 1;
        }
        return count;
    }

    private static boolean Perfect(int i) {
        int sum = 0;
        for (int j = 1; j < i; j++) {
            if (i % j == 0)
                sum += j;
        }
        return sum == i;
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] strings = str.split("-");
        String[] strings1 = strings[0].split(" ");
        String[] strings2 = strings[1].split(" ");
        //扑克牌大小，除了大小王
        String Pkp = "34567891JQKA2";

        //大小王直接输出
        if (strings[0].equals("joker JOKER") || strings[1].equals("joker JOKER")){
            System.out.println("joker JOKER");
        } else if (strings1.length == strings2.length) {
            //长度相等的情况下，判断第一个牌的大小
            if (Pkp.indexOf(strings[0].substring(0,1)) > Pkp.indexOf(strings[1].substring(0,1))){
                System.out.println(strings[0]);
            }else {
                System.out.println(strings[1]);
            }
        } else if (strings1.length == 4) {
            System.out.println(strings[0]);
        }else if (strings2.length == 4){
            System.out.println(strings[1]);
        }else {
            System.out.println("ERROR");
        }
    }
}
